module.exports = (app) => {
  // 登录和注册
  const web_router_login = require("./login");
  const web_router_register = require("./register");
  const web_router_car = require("./car");
  const web_router_category = require("./category");
  const web_router_article = require("./forum");
  const web_router_collect = require("./collect");
  const web_router_user = require("./user");
  const web_router_shop = require("./shop");
  const web_router_connect = require("./connect");

  app.use("/web/api", web_router_login);
  app.use("/web/api", web_router_register);
  app.use("/web/api", web_router_car);
  app.use("/web/api", web_router_category);
  app.use("/web/api", web_router_article);
  app.use("/web/api", web_router_collect);
  app.use("/web/api", web_router_user);
  app.use("/web/api/shop", web_router_shop);
  app.use("/web/api/connect", web_router_connect);

  /**
   * 文件上传接口
   */
  const multer = require("multer");
  const MAO = require("multer-aliyun-oss");
  const upload = multer({
    storage: MAO({
      config: {
        region: "oss-cn-shanghai",
        accessKeyId: "LTAI4GJY5R2U9bn9nyCw2V1j",
        accessKeySecret: "gwxcjPG3FFRdYzZnbRjByuqA4gjSee",
        bucket: "lyn-cars",
      },
    }),
  });

  app.post("/web/api/upload", upload.single("file"), async (req, res) => {
    const file = req.file;
    res.send(file);
  });

  //错误处理函数
  app.use(async (err, req, res, next) => {
    res.status(err.statusCode || 500).send({
      message: err.message,
    });
  });
};
